import { ElMessage, ElNotification, ElMessageBox } from "element-plus";
//自定义提示消息
export const messageUtils = {
  notificationSuccess(msg) {
    ElNotification.success({
      title: "Success",
      message: msg,
      offset: 100,
      duration: 5000,
      "show-close": true,
    });
  },
  notificationWarning(msg) {
    ElNotification({
      type: "warning",
      title: "Warning",
      message: msg,
      offset: 100,
      duration: 5000,
      "show-close": true,
    });
  },
  notificationInfo(msg) {
    ElNotification.info({
      title: "Tip",
      message: msg,
      offset: 100,
      duration: 5000,
      showClose: true,
    });
  },
  notificationError(msg) {
    ElNotification.error({
      title: "Error",
      message: msg,
      offset: 100,
      duration: 5000,
      showClose: true,
    });
  },
  messageSuccess(msg) {
    ElMessage.success({
      message: msg,
      showClose: true,
    });
  },
  messageWarning(msg) {
    ElMessage({
      type: "warning",
      message: msg,
      showClose: true,
    });
  },
  messageInfo(msg) {
    ElMessage({
      message: msg,
      showClose: true,
    });
  },
  messageError(msg) {
    ElMessage.error({
      message: msg,
      showClose: true,
    });
  },
  //删除提示框  第一参数删除的方法 传进来的值要带参数
  //第二个参数是刷新列表的方法  没有的话可以传个空的方法
  //第三个参数是prox对象  调用执行提示用的
  ElMessageBoxDeleteTips(deleteFunc, refreshTableFunc, proxy, deleteIds) {
    ElMessageBox({
      title: "提示",
      message: "确定要删除吗？",
      showCancelButton: true,
      confirmButtonText: "确定",
      cancelButtonText: "取消",
      type: "warning",
      beforeClose: async (action, instance, done) => {
        if (action === "confirm") {
          instance.confirmButtonLoading = true;
          instance.confirmButtonText = "Loading...";
          let res = await deleteFunc(deleteIds);
          if (res.success) {
            instance.confirmButtonLoading = false;
            proxy.$notify.success({ message: res.msg, showClose: true });
            //刷新列表
            refreshTableFunc();
          } else {
            proxy.$notify.error({ message: res.msg, showClose: true });
          }
        }
        done(); //关闭comfirm
      },
    }).catch((err) => {});
  },
};
